<%--
  Created by IntelliJ IDEA.
  User: 步步为莹
  Date: 2019/9/17
  Time: 9:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Beyond车辆管理平台</title>
    <link rel="stylesheet" href="../../../static/css/style.css">
    <link rel="stylesheet" href="../../../static/css/jquery.wysiwyg.old-school.css">
    
    <!-- jQuery AND jQueryUI -->
    <script type="text/javascript" src="../../../static/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../../static/js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="../../../static/js/min.js"></script>
    <!--<script type="text/javascript" src="js/index.js"></script>-->
</head>
<body>
<script type="text/javascript" src="../../../static/js/main.js"></script>
<link rel="stylesheet" href="../../../static/css/style2.css">
<div id="content" class="white">
    <h1><img src="../../../static/images/users1.png" alt="">数据字典</h1>
    <div class="bloc">
        <div class="title"> 操作 <a class="toggle"></a></div>
        <div class="content dashboard">
            <div class="center" style="display: block; width: auto;">
                <a href="javascript:;" onclick="add()">新增字典</a>
                <a href="javascript:;">
                    批量删除 </a>
            </div>
        </div>
    </div>
    <div class="bloc">
        <div class="title">字典列表</div>
        <div class="content">
            <table>
                <thead>
                <tr>
                    <th><input type="checkbox" id="selectALL" onclick="selectAll(this)">全选</th>
                    <th>字典名称</th>
                    <th>字典的值</th>
                    <th>字典类型</th>
                    <th>类型名称</th>
                    <th>是否有效</th>
                    <th>备注</th>
                </tr>
                </thead>
                <tbody id="listdictionary">
                
                </tbody>
            </table>
        </div>
    </div>
</div>
<div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>
<script type="text/javascript">

    //加载字典列表
    loadUserlist(1);
    function loadUserlist(page) {
        $("tbody#listdictionary").html("");
        $.ajax({
            url: "<%=request.getContextPath()%>/DictionaryServlet",
            type: "GET",
            data: "opr=listDictionary&startRow=" + (page - 1) * 7 + "&pageSize=7",
            dataType: "json",
            success: function (result) {
                console.log(result);
                var stuUser = "";
                $.each(result[1], function (index, ele) {
                    stuUser += "<tr>";
                    stuUser += "<td><input type='checkbox' class='Id'><input type='hidden' value='" + ele.id + "'> </td>"
                    stuUser += "<td>" + ele.name + "</td>";
                    stuUser += "<td>" + ele.value + "</td>";
                    stuUser += "<td>" + ele.type_Id + "</td>";
                    stuUser += "<td>" + ele.type_name + "</td>";
                    stuUser += "<td>" + ele.is_valid + "</td>";
                    stuUser += "<td>" + ele.remark + "</td>";
                    stuUser += "<td><a href='javascript:;' title='修改' onclick='update(this)'>\n" +
                        "<img src='../../../static/images/edit.png'></a>\n" +
                        "<a href='javascript:;' title='删除' onclick='del(this)'>\n" +
                        "<img src='../../../static/images/delete.png'></a></td>";
                    stuUser += "</tr>";
                });
                var pageStr = "";
                if (result[0][1] > 1) {
                    if (page == 1) {
                        pageStr += "<tr>";
                        pageStr +=
                            "<td><a href='javascript:;' onclick='loadUserlist(" + eval(parseInt(page) + 1) + ")'>下一页</a></td>";
                        pageStr += "<td><a href='javascript:;' onclick='loadUserlist(" +
                            result[0][1] + ")'>末页</a></td>";
                    } else if (page == result[0][1]) {
                        pageStr += "<tr>";
                        pageStr += "<td><a href='javascript:;' onclick='loadUserlist(1)'>首页</a></td>";
                        pageStr += "<td><a href='javascript:;' onclick='loadUserlist(" + eval(page - 1) + ")'>上一页</a></td>";
                    } else if (page > 1 && page < result[0][1]) {
                        pageStr += "<tr>";
                        pageStr += "<td><a href='javascript:;' onclick='loadUserlist(1)'>首页</a></td>";
                        pageStr += "<td><a href='javascript:;' onclick='loadUserlist(" + eval(page - 1) + ")'>上一页</a></td>";
                        pageStr += "<td><a href='javascript:;' onclick='loadUserlist(" + eval(parseInt(page) + 1) + ")'>下一页</a></td>";
                        pageStr += "<td><a href='javascript:;' onclick='loadUserlist(" + result[0][1] + ")'>尾页</a></td>";
                    }
                    pageStr += "</tr><tr>"
                    pageStr += "<td>总记录数" + result[0][0] + "条</td><td>每页7条</td>";
                    pageStr += "<td>页数" + page + "/" + result[0][1] + "页</td>";
                    pageStr += "</tr>";
                }
                $("tbody#listdictionary").append(stuUser);
                $("tbody#listdictionary").append(pageStr);
            }

        });
    }
    
    //其他复选框取消选中时全选取消
    function checkFalse(obj){
        if(!$(this).is(":checked")){
            $("#selectALL").prop("checked",false);
        }
    }

    //全选
    function selectAll(obj){
        //prop() 方法设置或返回被选元素的属性和值
        if($(obj).is(':checked')){
            $(":checkbox").prop("checked",true);
        }else {
            $(":checkbox").prop("checked",false);
        }
    };
    
    function add() {
        window.location.href="roleAdd.jsp";
    }
    
</script>

</body>
</html>
